//
//  Clock.cpp
//  GL_test_cpp
//
//  Created by Garrett Manka on 9/13/11.
//  Copyright 2011. All rights reserved.
//

#include <sim/Clock.h>

namespace Utilities 
{
    Clock::Clock() : m_isPaused(false)
    {
		#ifdef WIN32

		QueryPerformanceFrequency(&frequency);
		startCount.QuadPart = 0;
		endCount.QuadPart = 0;

		#else

		m_startCount.tv_sec = 0;
		m_startCount.tv_usec = 0;
        m_endCount.tv_sec = 0;
        m_endCount.tv_usec = 0;

		#endif
    }
    
    void Clock::markCurrentTime()
    {
		#ifdef _WIN32

		QueryPerformanceCounter(&startCount);

		#else

		gettimeofday(&m_startCount, NULL);
        m_startTime_usec = m_startCount.tv_sec * 1e+6 + m_startCount.tv_usec;

		#endif
    }
    
    double Clock::getTimeInSecondsFromMark()
    {
		#ifdef _WIN32

        QueryPerformanceCounter(&endCount);

		double startTimeInMicroSec = startCount.QuadPart * (1000000.0 / frequency.QuadPart);
		double endTimeInMicroSec = endCount.QuadPart * (1000000.0 / frequency.QuadPart);

		return (endTimeInMicroSec - startTimeInMicroSec) / 100000.0;

		#else

        gettimeofday(&m_endCount, NULL);
        m_endTime_usec = m_endCount.tv_sec * 1e+6 + m_endCount.tv_usec;
        
        return (m_endTime_usec - m_startTime_usec) / 1e+6;

		#endif
    }
}